<template>
  <div>
    <el-row>
      <el-col :span="24" style="margin:5px 0">
        <el-button @click="previousPage" style="float:right; " type="success" plain icon="el-icon-arrow-left">
          返回</el-button>
      </el-col>
    </el-row>
    <el-row v-if="FormName=='login'">
      <el-col :span="24">
        <el-form ref="loginForm" :model="loginForm" label-width="120px">
          <el-form-item label="策略名称：">
            <el-input v-model="loginForm.name" style="width:250px"></el-input>
          </el-form-item>
          <el-form-item label="策略操作：">
            <el-switch v-model="loginForm.disable" active-text="开启" inactive-text="不启用" active-value="1" inactive-value="0" disabled>
            </el-switch>
          </el-form-item>
          <el-form-item label="登录操作：">
            <el-switch v-model="loginForm.Logon.login" active-text="审计" inactive-text="不审计" active-value="1" inactive-value="0">
            </el-switch>
          </el-form-item>
          <el-form-item label="注销操作：">
            <el-switch v-model="loginForm.Logon.logout" active-text="审计" inactive-text="不审计" active-value="1" inactive-value="0">
            </el-switch>
          </el-form-item>
          <el-form-item label="开机操作：">
            <el-switch v-model="loginForm.Logon.boot" active-text="审计" inactive-text="不审计" active-value="1" inactive-value="0">
            </el-switch>
          </el-form-item>
          <el-form-item label="关机操作：">
            <el-switch v-model="loginForm.Logon.shutdown" active-text="审计" inactive-text="不审计" active-value="1" inactive-value="0">
            </el-switch>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="loginSubmit">确定</el-button>
            <el-button @click="cancelHandle">取消</el-button>
          </el-form-item>
        </el-form>
      </el-col>

    </el-row>
    <el-row v-if="FormName=='Account'">
      <el-col :span="24">
        <el-form ref="AccountForm" :model="AccountForm" label-width="120px">
          <el-form-item label="策略名称">
            <el-input v-model="AccountForm.name" style="width:250px"></el-input>
          </el-form-item>
          <el-form-item label="策略操作：">
            <el-switch v-model="AccountForm.disable" active-text="开启" inactive-text="不启用" active-value="1" inactive-value="0" disabled>
            </el-switch>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="AccountSubmit">确定</el-button>
            <el-button @click="cancelHandle">取消</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-row v-if="FormName=='Software'">
      <el-col :span="24">
        <el-form ref="SoftwareForm" :model="SoftwareForm" label-width="120px">
          <el-form-item label="策略名称">
            <el-input v-model="SoftwareForm.name" style="width:250px"></el-input>
          </el-form-item>
          <el-form-item label="软件变更审计">
            <el-radio-group v-model="SoftwareForm.disable" disabled>
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="SoftwareSubmit">确定</el-button>
            <el-button @click="cancelHandle">取消</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-row v-if="FormName=='Hardware'">
      <el-col :span="24">
        <el-form ref="HardwareForm" :model="HardwareForm" label-width="120px">
          <el-form-item label="策略名称">
            <el-input v-model="HardwareForm.name" style="width:250px"></el-input>
          </el-form-item>
          <el-form-item label="硬件变更审计">
            <!-- <el-switch v-model="HardwareForm.disable" active-color="#13ce66" inactive-color="#ff4949" active-value="1"
              inactive-value="0">
            </el-switch> -->
            <el-radio-group v-model="HardwareForm.disable" disabled>
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="HardwareSubmit">确定</el-button>
            <el-button @click="cancelHandle">取消</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  name: "",
  data() {
    return {
      FormName: "",
      rowData: {},
      loginForm: {
        type: "logon",
        disable: "0",
        name: "test",
        Logon: {
          login: "1",
          logout: "1",
          boot: "1",
          shutdown: "1",
        },
      },
      AccountForm: {
        name: "",
        disable: "1",
        type: "",
      },
      SoftwareForm: {
        disable: "0",
        name: "",
        type: "softwarechanged",
      },
      HardwareForm: {
        disable: "0",
        name: "",
        type: "hardwarechanged",
      },
    };
  },
  created() {
    this.gettypeName(this.$route.params.type, this.$route.params.row);
  },
  mounted() {},
  methods: {
    //返回上一页
    previousPage() {
      this.$router.go(-1);
    },
    onSubmit() {
      console.log("submit!");
    },
    gettypeName(type, row) {
      //  //系统登录监控
      if (type == "login") {
        this.FormName = type;
        this.rowData = row;
        if (JSON.stringify(row) !== "{}") {
          this.loginForm = row.Root.Policy;
        }
      } else if (type == "Account") {
        //
        this.FormName = type;
        this.rowData = row;
        if (JSON.stringify(row) !== "{}") {
          this.AccountForm.name = row.Root.Policy.name;
          this.AccountForm.type = row.Root.Policy.type;
          console.log(this.AccountForm);
        }
      } else if (type == "Software") {
        //软件变更监控
        this.FormName = type;
        if (JSON.stringify(row) !== "{}") {
          this.SoftwareForm = row.Root.Policy;
        }
      } else if (type == "Hardware") {
        //硬件变更监控
        this.FormName = type;
        if (JSON.stringify(row) !== "{}") {
          this.HardwareForm = row.Root.Policy;
        }
        // this.loginForm = row
      }
    },
    HardwareSubmit() {
      this.$confirm("确认要提交吗？", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      })
        .then(() => {
          if (JSON.stringify(this.$route.params.row) == "{}") {
            this.HardwareForm.disable = "0";
            this.rowData = {
              Policy: {
                Root: {
                  Policy: this.HardwareForm,
                },
                creator: "secadm",
                enableTime: "",
                name: this.HardwareForm.name,
                // state:
                state: "1",
              },
            };
          } else {
            this.HardwareForm.disable = "0";
            this.rowData = {
              Policy: {
                Root: {
                  Policy: this.HardwareForm,
                },
                creator: "secadm",
                enableTime: "",
                name: this.HardwareForm.name,
                state: "1",
                // state: this.HardwareForm.disable
              },
            };
          }
          this.$postForJson("/sjrj/policy/hardwarechanged", this.rowData).then(
            (res) => {
              console.log(res, "sss");
              this.$message({
                type: "success",
                message: "提交成功！",
              });
              this.$router.go(-1);
            }
          );
        })
        .catch((_) => {
          this.$message({
            type: "info",
            message: "已取消提交",
          });
        });
    },
    SoftwareSubmit() {
      this.$confirm("确认要提交吗？", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "提交成功！",
          });
          if (JSON.stringify(this.$route.params.row) == "{}") {
            this.SoftwareForm.disable = "0";
            this.rowData = {
              Policy: {
                creator: "secadm",
                enableTime: "",
                name: this.SoftwareForm.name,
                state: "1",
                // state: this.SoftwareForm.disable,
                Root: {
                  Policy: this.SoftwareForm,
                },
              },
            };
            //
          } else {
            this.SoftwareForm.disable = "0";
            this.rowData = {
              Policy: {
                creator: "secadm",
                enableTime: "",
                name: this.SoftwareForm.name,
                state: "1",
                // state: this.SoftwareForm.disable,
                Root: {
                  Policy: this.SoftwareForm,
                },
              },
            };
          }
          this.$postForJson("/sjrj/policy/softwarechanged", this.rowData).then(
            (res) => {
              console.log(res, "sss");
            }
          );
          this.$router.go(-1);
        })
        .catch((_) => {
          this.$message({
            type: "info",
            message: "已取消提交",
          });
        });
    },
    AccountSubmit() {
      this.$confirm("确认要提交吗？", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      })
        .then(() => {
          if (JSON.stringify(this.$route.params.row) == "{}") {
            this.AccountForm.disable = "0";
            this.rowData = {
              Policy: {
                creator: "secadm",
                enableTime: "",
                name: this.AccountForm.name,
                state: "1",
                // state:  this.AccountForm.disable,
                Root: {
                  Policy: this.AccountForm,
                },
              },
            };
          } else {
            this.AccountForm.disable = "0";
            this.rowData = {
              Policy: {
                creator: "secadm",
                enableTime: "",
                name: this.AccountForm.name,
                // state: this.AccountForm.disable,
                state: "1",
                Root: {
                  Policy: this.AccountForm,
                },
              },
            };
          }
          this.$postForJson("/sjrj/policy/sysaccount", this.rowData).then(
            (jsonData) => {
              console.log(jsonData, "sss");
              this.$message({
                type: "success",
                message: "提交成功！",
              });
              this.$router.go(-1);
            }
          );
        })
        .catch((_) => {
          this.$message({
            type: "info",
            message: "已取消提交",
          });
        });
    },
    loginSubmit() {
      this.$confirm("确认要提交吗？", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      })
        .then(() => {
          console.log(this.$route.params.row);
          if (JSON.stringify(this.$route.params.row) == "{}") {
            this.loginForm.disable = "0";
            this.rowData = {
              Policy: {
                creator: "secadm",
                enableTime: "",
                name: this.loginForm.name,
                // state: this.loginForm.disable,
                state: "1",
                Root: {
                  Policy: this.loginForm,
                },
              },
            };
          } else {
            this.loginForm.disable = "0";
            this.rowData = {
              Policy: {
                creator: "secadm",
                enableTime: "",
                name: this.loginForm.name,
                //  state: this.loginForm.disable,
                state: "1",
                Root: {
                  Policy: this.loginForm,
                },
              },
            };
          }
          this.$postForJson("/sjrj/policy/syslogin", this.rowData).then(
            (jsonData) => {
              console.log(jsonData, "sss");
              this.$message({
                type: "success",
                message: "提交成功！",
              });
              this.$router.go(-1);
            }
          );
        })
        .catch((_) => {
          this.$message({
            type: "info",
            message: "已取消提交",
          });
        });
    },
    //取消按钮
    cancelHandle() {
      this.$router.go(-1);
    },
  },
};
</script>
 